package gui;

/*
 * Esse arquivo é parte do Software new Recicle
 * 
 * Copyright (C) 2011-$AnoCorrente$ Eduardo Moreira Barbosa
 * Copyright (C) 2011-$AnoCorrente$ João dos Santos Gonçalves
 * Copyright (C) 2011-$AnoCorrente$ Lucas Ximenes da Fonseca
 * 
 * new Recicle é um Software Livre: Você pode redistribuí-lo e/ou modificá-lo
 * de acordo com os termos da Licença Pública Geral GNU (GNU General Public License)
 * conforme publicada pela Free Software Foundation (FSF). Essa permissão é atribuída
 * na versão 3 da Licença, ou (na sua opinião) qualquer versão.
 * 
 * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este programa,
 * se não, escreva para a Fundação do Software Livre(FSF) Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 * 
 * Se você tiver alguma dúvida e/ou quiser dar suporte ao desenvolvimento, favor entrar em
 * contato nos e-mails <barbosa.edrd@gmail.com>, <john.jsg@hotmail.com>, <lxf.lucas@gmail.com>.
 */

import bd.*;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import empresa.*;
import outros.Cnpj;


public class CadastrarEmpresa extends javax.swing.JDialog {

    protected static CadastrarEmpresa dialog;
    private static String selecionado;
    private boolean isEdicao = false; // Valor inicial

    public CadastrarEmpresa(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        defineIconesFrame(); // Icone da JFrame
        
        telefoneText.setFont(new java.awt.Font("Tahoma", 0, 15));
        

        String cancelName = "cancel";
        InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
         
    }
    
    public void setIsEdicao(boolean is) {
        isEdicao = is;
    }
    
    public void setSelecionado(String selecionado) {
        CadastrarEmpresa.selecionado = selecionado;
    }
    
    private void cEmpresa() {
        if ( nomeText.getText().length() > 2 ) {
            if ( Cnpj.calculaCnpj( cnpjText.getText() ) ) {
                if ( enderecoText.getText().length() > 4 ) {
                    if (!((emailText.getText().length() < 4)
                            || !emailText.getText().contains("@")
                            || !emailText.getText().contains("."))) {
                        
                        Empresa.getRegistro().setDataContato(dataContatoText.getText());
                        Empresa.getRegistro().setNome(nomeText.getText());
                        Empresa.getRegistro().setEndereco(enderecoText.getText());
                        Empresa.getRegistro().setBairro(bairroText.getText());
                        Empresa.getRegistro().setCep(cepText.getText());
                        Empresa.getRegistro().setCidade(cidadeText.getText());
                        Empresa.getRegistro().setEstado(estadoText.getText());
                        Empresa.getRegistro().setEmail(emailText.getText());
                        Empresa.getRegistro().setTelefone(telefoneText.getText());
                        Empresa.getRegistro().setNumeroEmpregados(noFunciorariosText.getText());
                        Empresa.getRegistro().setTempoAtuacao(tatuacaoText.getText());
                        Empresa.getRegistro().setCnpj(cnpjText.getText());
                        
                        BancoEmpresa bancoEmpresa = new BancoEmpresa();
                        BancoDeDados bancoDeDados = new BancoDeDados();
                        bancoDeDados.conectarBanco();
                        
                        bancoEmpresa.cadastrar();
                        
                        this.dispose();
                    } else {
                        avisos.setText("Aviso!: O e-mail é inválido, verifique se esta correto...");
                    }
                } else {
                    avisos.setText("Aviso!: O enderenço é inválido! Deve ter pelo menos 5 letras...");
                }

            } else {
                avisos.setText("Aviso!: CNPJ inválido! Corrija e tente novamente...");
            }

        } else {
            avisos.setText("Aviso!: Nome da muito curto! Deve ter pelo menos 3 letras...");
        }
    }

    private void eEmpresa(String nomeSelecionado) {
        if ( nomeText.getText().length() > 2 ) {
            if ( Cnpj.calculaCnpj( cnpjText.getText() ) ) {
                if ( enderecoText.getText().length() > 4 ) {
                    if (!((emailText.getText().length() < 4)
                            || !emailText.getText().contains("@")
                            || !emailText.getText().contains("."))) {
                        
                    BancoEmpresa bancoEmpresa = new BancoEmpresa();
                    BancoDeDados bancoDeDados = new BancoDeDados();
                    bancoDeDados.conectarBanco();       
                    Empresa empresa = new Empresa();

                    empresa.setDataContato( dataContatoText.getText() );
                    empresa.setNome( nomeText.getText() );
                    empresa.setEndereco( enderecoText.getText() );
                    empresa.setBairro( bairroText.getText() );
                    empresa.setCep( cepText.getText() );
                    empresa.setCidade( cidadeText.getText() );
                    empresa.setEstado(estadoText.getText() );
                    empresa.setEmail( emailText.getText() );
                    empresa.setTelefone( telefoneText.getText() );
                    empresa.setNumeroEmpregados( noFunciorariosText.getText() );
                    empresa.setTempoAtuacao( tatuacaoText.getText() );
                    empresa.setCnpj( cnpjText.getText() );

                    /*
                     * Alteração no banco
                     */
                    bancoEmpresa.alterar(empresa, nomeSelecionado);
                    
                    /*
                     * Atualizar os botões
                     */
                    NewRecicle.atualizaBotoes();
                    /* 
                     * Volta ao padrão da variavel
                     */
                    isEdicao = false;
                    
                    this.dispose();
                    
                    
                    } else {
                        avisos.setText("Aviso!: O e-mail é inválido, verifique se esta correto...");
                    }
                } else {
                    avisos.setText("Aviso!: O enderenço é inválido! Deve ter pelo menos 5 letras...");
                }

            } else {
                avisos.setText("Aviso!: CNPJ inválido! Corrija e tente novamente...");
            }

        } else {
            avisos.setText("Aviso!: Nome da muito curto! Deve ter pelo menos 3 letras...");
        }
    }
    /**
     * 
     * @param dataContato
     * @param nome
     * @param endereco
     * @param bairro
     * @param cep
     * @param cidade
     * @param estado
     * @param email
     * @param telefone
     * @param noFuncionario
     * @param tempoAcao
     * @param cnpj 
     */
    public void editandoEmpresa(String dataContato, String nome, String endereco, String bairro,
            String cep, String cidade, String estado, String email, String telefone,
            String noFuncionario, String tempoAcao, String cnpj) {
        
        dataContatoText.setText( dataContato );
        nomeText.setText( nome );
        enderecoText.setText( endereco );
        bairroText.setText( bairro );
        cepText.setText( cep );
        cidadeText.setText( cidade );
        estadoText.setText( estado );
        emailText.setText( email );
        telefoneText.setText( telefone );
        noFunciorariosText.setText( noFuncionario );
        tatuacaoText.setText( tempoAcao );
    }
            
    private void defineIconesFrame(){
        try {

            this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/imagens/ervilha/Logo.png")));
        } catch (Exception e){
            e.printStackTrace();
        }
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        emailText = new javax.swing.JTextField();
        mensagem = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        enderecoText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        estadoText = new javax.swing.JFormattedTextField();
        tatuacaoText = new javax.swing.JTextField();
        telefoneText = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        avisos = new javax.swing.JLabel();
        cepText = new javax.swing.JFormattedTextField();
        nomeText = new javax.swing.JTextField();
        bairroText = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        dataContatoText = new javax.swing.JFormattedTextField();
        cnpjText = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        cidadeText = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        noFunciorariosText = new javax.swing.JFormattedTextField();
        okButton = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrado de Empresa");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        mensagem.setBackground(java.awt.Color.white);
        mensagem.setFont(new java.awt.Font("Tahoma", 0, 13));
        mensagem.setText("* Campo obrigatório!");

        jLabel4.setBackground(java.awt.Color.white);
        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel4.setText("Telefone: *");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel1.setText("Nome: *");

        try {
            estadoText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("**")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            telefoneText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel9.setBackground(java.awt.Color.white);
        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel9.setText("CEP: *");

        avisos.setFont(new java.awt.Font("Tahoma", 1, 12));
        avisos.setForeground(new java.awt.Color(255, 0, 0));
        avisos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        avisos.setText("#");

        try {
            cepText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        nomeText.setToolTipText("Ex.: José da Ascara");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel8.setText("Estado: *");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel5.setText("Bairro: *");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel11.setText("E-mail:");

        jLabel10.setBackground(java.awt.Color.white);
        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel10.setText("CNPJ: *");

        jLabel3.setBackground(java.awt.Color.white);
        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel3.setText("Endereço: *");

        try {
            dataContatoText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        dataContatoText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataContatoTextActionPerformed(evt);
            }
        });

        try {
            cnpjText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        cnpjText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnpjTextActionPerformed(evt);
            }
        });

        jLabel2.setBackground(java.awt.Color.white);
        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel2.setText("Tempo de Atuação: *");

        jLabel13.setBackground(java.awt.Color.white);
        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel13.setText("Data de Contato: *");

        okButton.setFont(new java.awt.Font("Tahoma", 1, 18));
        okButton.setText("Confirmar");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        jLabel7.setBackground(java.awt.Color.white);
        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel7.setText("Cidade: *");

        jLabel12.setBackground(java.awt.Color.white);
        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel12.setText("No. de funcionários: *");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(2, 2, 2)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(enderecoText, javax.swing.GroupLayout.PREFERRED_SIZE, 823, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(nomeText, javax.swing.GroupLayout.PREFERRED_SIZE, 823, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(65, 65, 65)
                                .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, 830, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 891, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(mensagem)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 325, Short.MAX_VALUE)
                                .addComponent(avisos, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel8))
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(estadoText, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel9)
                                                .addGap(18, 18, 18)
                                                .addComponent(cepText, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(bairroText, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(telefoneText)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(tatuacaoText, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(2, 2, 2)))
                                .addGap(16, 16, 16)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addGap(18, 18, 18)
                                        .addComponent(noFunciorariosText)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel13)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(dataContatoText, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cidadeText, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(cnpjText, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(364, 364, 364)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(10, 10, 10))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomeText, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enderecoText, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(bairroText, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cepText, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(estadoText, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cidadeText, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cnpjText, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(telefoneText, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(noFunciorariosText, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dataContatoText, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(tatuacaoText, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mensagem)
                    .addComponent(avisos, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        getRootPane().setDefaultButton(okButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
       
    }//GEN-LAST:event_closeDialog

    private void dataContatoTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataContatoTextActionPerformed

    }//GEN-LAST:event_dataContatoTextActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        if (isEdicao == false) {
            cEmpresa();
        } else if (isEdicao){
            eEmpresa(selecionado);
        }
    }//GEN-LAST:event_okButtonActionPerformed

    private void cnpjTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnpjTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cnpjTextActionPerformed

    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastrarEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastrarEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastrarEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastrarEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                dialog = new CadastrarEmpresa(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel avisos;
    private javax.swing.JTextField bairroText;
    private javax.swing.JFormattedTextField cepText;
    private javax.swing.JTextField cidadeText;
    private javax.swing.JFormattedTextField cnpjText;
    private javax.swing.JFormattedTextField dataContatoText;
    private javax.swing.JTextField emailText;
    private javax.swing.JTextField enderecoText;
    private javax.swing.JFormattedTextField estadoText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel mensagem;
    private javax.swing.JFormattedTextField noFunciorariosText;
    private javax.swing.JTextField nomeText;
    private javax.swing.JButton okButton;
    private javax.swing.JTextField tatuacaoText;
    private javax.swing.JFormattedTextField telefoneText;
    // End of variables declaration//GEN-END:variables
}
